<?php

namespace app\admin\controller;

use app\common\controller\Backend;

/**
 * 其他管理
 *
 * @icon fa fa-circle-o
 */
class Other extends Backend {

    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */
    //平台协议
    public function ptxy() {
        $config_key = 'pintaixieyi';
        if ($this->request->isPost()) {
            $data['desc'] = input('desc');
            $data['update_time'] = time();
            \think\Db::name('configure')->where(['key' => $config_key])->update($data);
            $this->success();
        }
        $data = \think\Db::name('configure')->where(['key' => $config_key])->find();
        $this->assign('data', $data);
        return $this->view->fetch();
    }

    //其他配置
    public function xgpz() {
        $config_key = 'xiangguanpeizhi';
        if ($this->request->isPost()) {
            $data['rakeback_rate'] = input('rakeback_rate');     //返佣比例
            $data['min_tixian'] = input('min_tixian');     //最小提现
            $data['tixian_deduct'] = input('tixian_deduct');     //提现扣除比例
            $data['pt_phone'] = input('pt_phone');     //平台电话
            $data['onoff_first_price'] = input('onoff_first_price');     //首次商家发布任务奖励开关： 0-关闭 1-开启
            $data['first_price'] = input('first_price');     //首次商家发布任务奖励金额
            $addData['desc'] = json_encode($data);
            $addData['update_time'] = time();
            \think\Db::name('configure')->where(['key' => $config_key])->update($addData);
            $this->success();
        }
        $data = \think\Db::name('configure')->where(['key' => $config_key])->find();
        $data['desc'] = json_decode($data['desc'],TRUE);
        if (empty($data['desc'])) {
            !isset($data['rakeback_rate']) && $data['rakeback_rate'] = '';     //返佣比例
            !isset($data['min_tixian']) && $data['min_tixian'] = '';     //最小提现
            !isset($data['tixian_deduct']) && $data['tixian_deduct'] = '';     //提现扣除比例
            !isset($data['pt_phone']) && $data['pt_phone'] = '';     //平台电话
            !isset($data['onoff_first_price']) && $data['onoff_first_price'] = '';     //首次商家发布任务奖励开关： 0-关闭 1-开启
            !isset($data['first_price']) && $data['first_price'] = '';     //首次商家发布任务奖励金额
        }
        $this->assign('data', $data['desc']);
        return $this->view->fetch();
    }

}
